<?php
/**
 * Created by PhpStorm.
 * User: xushengbin
 * Date: 2017/12/13
 * Time: PM10:58
 */

namespace app\components;

use Yii;

class LoginStateComponent extends \yii\base\Component
{
    public function checkLogin()
    {
        return Yii::$app->session->get('userId');
    }
    public function getState($key)
    {
        return Yii::$app->session->get($key);
    }
    public function saveSession($loginResult, $userName)
    {
        Yii::$app->session->set('username', $userName);
        Yii::$app->session->set('userId', $loginResult['userId']);
        Yii::$app->session->set('sessionId', $loginResult['sessionId']);
        Yii::$app->session->set('role', $loginResult['role']);
    }
    public function clearSession()
    {
        Yii::$app->session->remove('username');
        Yii::$app->session->remove('userId');
        Yii::$app->session->remove('sessionId');
        Yii::$app->session->remove('role');
    }
}